﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Subjects;
using System.Text;

namespace Frogs.Stability.CircuitBreaker.Behaviors.Functions
{
	class ClosedBehavior : IFunctionCircuitBehavior
	{
		public T DoFunction<T>(Func<T> func)
		{
			try
			{
				T value = func();
				this._executionResult.OnNext(Behaviors.ExecutionResult.Success);
				return value;
			}
			catch
			{
				this._executionResult.OnNext(Behaviors.ExecutionResult.Fail);
				throw;
			}
		}

		public CircuitState GetStatus()
		{
			return CircuitState.Closed;
		}

		Subject<ExecutionResult> _executionResult = new Subject<ExecutionResult>();
		public IObservable<ExecutionResult> ExecutionResult { get { return this._executionResult; } }
	}
}
